import { TOKEN } from '@/components/constants.js';
import { ref } from 'vue';

let parseToken = '';
try {
  parseToken = JSON.parse(TOKEN);
} catch {
  parseToken = '';
}

const useToken = () => {
  const token = ref(parseToken);

  const setToken = (tk) => {
    token.value = tk;
    localStorage.setItem(TOKEN, tk);
  };

  return {
    token,
    setToken,
  };
};

export default useToken;
